package com.code.qgjx.service.impl;

import com.code.qgjx.entity.StudentJob;
import com.code.qgjx.mapper.StudentJobMapper;
import com.code.qgjx.service.StudentJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class StudentJobServiceImpl implements StudentJobService {

    @Autowired
    private StudentJobMapper studentJobMapper;

    @Override
    public boolean applyJob(StudentJob studentJob) {
        studentJob.setStatus(0);
        return studentJobMapper.insert(studentJob) > 0;
    }

    @Override
    public boolean quitJob(Long userId, Long jobPositionId) {
        StudentJob studentJob = new StudentJob();
        studentJob.setUserId(userId);
        studentJob.setJobPositionId(jobPositionId);
        studentJob.setStatus(-1);
        return studentJobMapper.updateStatus(studentJob) > 0;
    }

    @Override
    public boolean updateJobStatus(StudentJob studentJob) {
        return studentJobMapper.updateStatus(studentJob) > 0;
    }

    @Override
    public List<Map<String, Object>> getStudentJobsWithDetails(Long userId, int start, int limit, String departmentName,Integer statusId) {
        // TODO: 需要在 mapper 中添加按科室名称筛选的功能
        return studentJobMapper.selectByUserIdWithDetails(userId, start, limit,statusId);
    }

    @Override
    public int getStudentJobCountWithDetails(Long userId, String departmentName,Integer statusId) {
        // TODO: 需要在 mapper 中添加按科室名称筛选的功能
        return studentJobMapper.selectCountByUserIdWithDetails(userId,statusId);
    }

    @Override
    public List<StudentJob> getStudentJobs(Long userId) {
        return studentJobMapper.selectByUserId(userId);
    }

    @Override
    public List<StudentJob> getJobStudents(Long jobPositionId) {
        return studentJobMapper.selectByJobPositionId(jobPositionId);
    }

    @Override
    public StudentJob getStudentJob(Long userId, Long jobPositionId) {
        return studentJobMapper.selectByUserIdAndJobId(userId, jobPositionId);
    }

    @Override
    public List<StudentJob> getAllStudentJobs() {
        return studentJobMapper.selectAll();
    }

    @Override
    public List<StudentJob> getAllStudentJobsWithPage(int start, int limit) {
        return studentJobMapper.selectAllWithPage(start, limit);
    }

    @Override
    public List<StudentJob> getStudentJobsWithPage(Long userId, int start, int limit) {
        return studentJobMapper.selectByUserIdWithPage(userId, start, limit);
    }

    @Override
    public List<StudentJob> getJobStudentsWithPage(Long jobPositionId, int start, int limit) {
        return studentJobMapper.selectByJobPositionIdWithPage(jobPositionId, start, limit);
    }

    @Override
    public List<StudentJob> getStudentJobsByStatusWithPage(Integer status, int start, int limit) {
        return studentJobMapper.selectByStatusWithPage(status, start, limit);
    }

    @Override
    public int getStudentJobCount() {
        return studentJobMapper.selectCount();
    }

    @Override
    public int getStudentJobCountByUserId(Long userId) {
        return studentJobMapper.selectCountByUserId(userId);
    }

    @Override
    public int getStudentJobCountByJobPositionId(Long jobPositionId) {
        return studentJobMapper.selectCountByJobPositionId(jobPositionId);
    }

    @Override
    public int getStudentJobCountByStatus(Integer status) {
        return studentJobMapper.selectCountByStatus(status);
    }
} 